package com.ys.nms.module.business.service.sysLog;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.ys.nms.module.business.controller.admin.sysLog.vo.*;
import com.ys.nms.module.business.dal.dataobject.sysLog.SysLogDO;
import com.ys.nms.framework.common.pojo.PageResult;
import com.ys.nms.framework.common.pojo.PageParam;
import com.ys.nms.framework.common.util.object.BeanUtils;

import com.ys.nms.module.business.dal.mysql.sysLog.SysLogMapper;

import static com.ys.nms.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.ys.nms.framework.common.util.collection.CollectionUtils.convertList;
import static com.ys.nms.framework.common.util.collection.CollectionUtils.diffList;
import static com.ys.nms.module.business.enums.ErrorCodeConstants.*;

/**
 * 系统日志 Service 实现类
 *
 * @author zzy
 */
@Service
@Validated
public class SysLogServiceImpl implements SysLogService {

    @Resource
    private SysLogMapper sysLogMapper;

    @Override
    public Long createSysLog(SysLogSaveReqVO createReqVO) {
        // 插入
        SysLogDO sysLog = BeanUtils.toBean(createReqVO, SysLogDO.class);
        sysLogMapper.insert(sysLog);

        // 返回
        return sysLog.getSeq();
    }

    @Override
    public void updateSysLog(SysLogSaveReqVO updateReqVO) {
        // 校验存在
        validateSysLogExists(updateReqVO.getSeq());
        // 更新
        SysLogDO updateObj = BeanUtils.toBean(updateReqVO, SysLogDO.class);
        sysLogMapper.updateById(updateObj);
    }

    @Override
    public void deleteSysLog(Long id) {
        // 校验存在
        validateSysLogExists(id);
        // 删除
        sysLogMapper.deleteById(id);
    }

    @Override
        public void deleteSysLogListByIds(List<Long> ids) {
        // 删除
        sysLogMapper.deleteByIds(ids);
        }


    private void validateSysLogExists(Long id) {
        if (sysLogMapper.selectById(id) == null) {
            throw exception(SYS_LOG_NOT_EXISTS);
        }
    }

    @Override
    public SysLogDO getSysLog(Long id) {
        return sysLogMapper.selectById(id);
    }

    @Override
    public PageResult<SysLogDO> getSysLogPage(SysLogPageReqVO pageReqVO) {
        return sysLogMapper.selectPage(pageReqVO);
    }

}